package com.test.sdk.provider.util;

import java.util.*;

public class SignUtil {

    public static String signStr(Map<String, String[]> params) {
        List<String> keys = new ArrayList<>(params.keySet());
        Collections.sort(keys);
        StringBuilder builder = new StringBuilder();
        for (String key : keys) {
            if("sign".equals(key)){
                continue;
            }
            builder.append(key).append("=");
            String[] values = params.get(key);
            if (values != null && values.length > 0) {
                builder.append(values[0]);
            }
            builder.append("&");
        }
        return builder.toString();
    }

    public static String sign(String str){
        return DigestUtils.getMD5(str+SdkConstants.REQUEST_SALT);
    }

}
